<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>还款申请</title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
	a:link{text-decoration: none; color:blue; font-family: 微软雅黑;}
	a:visited{color:green;}
	a:hover{text-decoration: underline; color:#09f;}
	a:active{text-decoration: blink; color: yellow;}
</style>
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div id="pageInTab" class="pageInTab">
			<form id="fnc_prj_pay_schmd_form">
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">项目基础信息</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">项目名称</div>
						<div class="field">
							<!-- <span name="FNCPRJNM" id="FNCPRJNM" >${bscinfo.FNCPRJNM}</span> -->
							<c:if test="${pianflag==null||pianflag=='' }">
							<a  id="FNCPRJNM" href="javascript:detailBtn('${bscinfo.PID}')">${bscinfo.FNCPRJNM}</a>
							</c:if>
							<c:if test="${pianflag=='101' }">
							${bscinfo.FNCPRJNM}
							</c:if>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">项目编号</div>
						<div class="field">
							<span name="FNCPRJID" id="FNCPRJID" >${bscinfo.FNCPRJID}</span>
							<input type="hidden" id="payschid" name="payschid" value="${bscinfo.SCHDID}">
							<input type="hidden" id="oper" name="oper" value="${oper}">
							<input type="hidden" id="jrnlid" name="jrnlid" value="${jrnlid}" >
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">创建日期</div>
						<div class="field">
							<span name="CRTTM" id="CRTTM" >${bscinfo.CRTTM}</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">融资机构</div>
						<div class="field">
							<span name="FUNDRASINSNM" id="FUNDRASINSNM" >${bscinfo.FUNDRASINSNM}</span>
							<input type="hidden" id="fundrasinsid" name="fundrasinsid" value="${bscinfo.FUNDRASINSID}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">融资方案</div>
						<div class="field">
							<!-- <span name="FNCSCMNM" id="FNCSCMNM" >${bscinfo.FNCSCMNM}</span> -->
							<c:if test="${pianflag==null||pianflag=='' }">
							<a href="javascript:showDetail('${bscinfo.FNCSCMID}')" >${bscinfo.FNCSCMNM}</a>
							</c:if>
							<c:if test="${pianflag=='101' }">
							${bscinfo.FNCSCMNM}
							</c:if>
							<input type="hidden" id="fncscmid" name="fncscmid" value="${bscinfo.FNCSCMID}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">项目金额</div>
						<div class="field">
							<span name="FNCPRJAMT" id="FNCPRJAMT" >${bscinfo.FNCPRJAMT}</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">实际融资金额</div>
						<div class="field">
							<span name="FNCFIAMT" id="FNCFIAMT" >${bscinfo.ACFIAMT}</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">支付表数量</div>
						<div class="field">
							<span name="PAYCNT" id="PAYCNT" >${bscinfo.PAYCNT}</span>
						</div>
					</div>
					<!-- 外部机构用不显示这几个字段 -->
					
					<c:if test="${pianflag==null||pianflag=='' }">
					<div class="fieldBox col_50">
						<div class="label">方案XIRR(%)</div>
						<div class="field">
							<span name="FNCFIAMT" id="FNCFIAMT" >${bscinfo.IRR * 100}</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">实际XIRR(%)</div>
						<div class="field">
							<span name="PAYCNT" id="PAYCNT" >${bscinfo.ACXIRR}</span>
						</div>
					</div>
					
					<!-- 增加 报价利率（%）、实际利率（%） 字段 -->
					<div class="fieldBox col_50">
						<div class="label">报价利率(%)</div>
						<div class="field">
							<span name="SCMINTRT" id="SCMINTRT" >${bscinfo.SCMINTRT * 100}</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">实际利率(%)</div>
						<div class="field">
							<span name="SCMINTRTREAL" id="SCMINTRTREAL" >${bscinfo.SCMINTRTREAL * 100}</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">还本方式</div>
						<div class="field">
							<span name="repayTypeNm" id="repayTypeNm" >${bscinfo.repayTypeNm}</span>
						</div>
					</div>
					</c:if>
				</div>
				
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">融资端费用</span>
					</div>
					<div class="fieldBox col_100">
							<div id="cost0" class="sq-grid">
							</div>
					</div>
				</div>
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">还款明细</span>
					</div>
					<div class="fieldBox col_100">
							<div id="cost1" class="sq-grid">
							</div>
					</div>
				</div>
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="fieldBox col_100">
						<div class="label">还款本金合计</div>
						<div class="field">
							<input name="sumFeeAmt" id="sumFeeAmt" type="text" class="ui-textbox" disabled="disabled">
						</div>
					</div>
				</div>
			</form>
		</div>
	
	</div>
<!-- 嵌入账户详情 -->
<jsp:include page="../mrgnmanageinfo/showAcc.jsp"></jsp:include>
	<script type="text/javascript">
	
//	<c:if test="${oper =='pubview'}">
		var initCost0GridUrl = "<%=path%>/rfbase/fncprjpaysch/initCost0Grid.do?payschid=${bscinfo.SCHDID}";
		var initDetlGridUrl = "<%=path%>/rfbase/fncprjpaysch/initDetlGrid.do?payschid=${bscinfo.SCHDID}";
//	</c:if>
//	<c:if test="${oper !='pubview'}">
//		var initCost0GridUrl = "<%=path%>/rfbase/fncprjpaysch/initCost0JrnlGrid.do?jrnlid=${jrnlid}";
//		var initDetlGridUrl = "<%=path%>/rfbase/fncprjpaysch/initDetlJrnlGrid.do?jrnlid=${jrnlid}";
//	</c:if>
	
	var griddata0,griddata1;
	$(function () {
		initCost0Grid();
		initDetlGrid();
	});
	
    function initCost0Grid()
    {
    	griddata0 = $("#cost0").ligerGrid({
	    	url : initCost0GridUrl,
	    	method : 'get',
            columns: [
                { display: '费用名称', name: 'COST_NM', width: 160, type: 'text'},
                { display: '应还金额', name: 'FEE_AMT', width: 160, type: 'float'},
                { display: '已还金额', name: 'PAID_UP_AMT', width: 160, type: 'float'},
                { display: '剩余金额', name: 'AR_AMT', width: 160, type: 'float',
                    totalSummary:
                    {
                        render: function (suminf, column, cell)
                        {
                            return '<div>合计:' + suminf.sum + '</div>';
                        },
                        align: 'left'
                    }
    			},
                { display: '应还金额浮动', name: 'FLOAT_AMT',type: 'float', 
                    editor: { type: 'float' }, align: 'left', width: 160
                },
                { display: '本次还款额', name: 'ACTUAL_AMT',type: 'float', 
                    editor: { type: 'float' }, align: 'left', width: 160,
                    totalSummary:
                    {
                        render: function (suminf, column, cell)
                        {
                            return '<div>' + suminf.sum + '</div>';
                        },
                        align: 'left'
                    }
                },
                { display: '备注', name: 'FEE_REM', width: 200, type: 'text',align: 'left'
                },
                { display: '实际付款时间', name: 'ACT_PYMT_DT', width: 160, type: 'text'},
                { display: '实际付款金额', name: 'ACT_PYMT_AMT', width: 160, type: 'text'},
                { display: '机构收款账号', name: 'rcvpymtAccNo', width: 150, type: 'text',
                	render:function (rowdata, rowindex, value, column) { 
                		var h="";
    	            	if(rowdata.rcvpymtAccId!=null){
                			 h ="<a href='#' onclick='showInsAcc("+rowdata.rcvpymtAccId+")'> <font color='blue'>"+rowdata.rcvpymtAccNo+"</font></a>";
    	            	}
    	            	return h;
            		}
                }, 
                { display: '我司付款账户', name: 'payAccNm', width: 200, type: 'text'},
                
                { display: '我司付款账号', name: 'payAccNo', width: 200, type: 'text',
                	render:function (rowdata, rowindex, value, column) { 
    	            	var h="";
    	            	if(rowdata.payAccId!=null){
                		 h ="<a href='#' onclick='showSysAcc("+rowdata.payAccId+")'> <font color='blue'>"+rowdata.payAccNo+"</font></a>";
    	            	}
    	            	return h;
                	}
                },
                { display: '逻辑序号', name: 'ID',width:0, align:'left', hide:true}
            ],
            enabledEdit: false, isScroll: true,rownumbers:true,
            onAfterShowData: f_onAfterShowData0,
            width: '100%',height:160,checkbox:true,usePager:false
        });
    }
	
    function initDetlGrid()
    {
    	griddata1 = $("#cost1").ligerGrid({
	    	url : initDetlGridUrl,
	    	method : 'get',
            columns: [
            { display: '期数', name: 'payPd', width: 50, type: 'int' },
            { display: '应还款项', name: 'feeClsCd',width: 150, type: 'text',
                render: function (item)
                {
                    if (parseInt(item.feeClsCd) == 1) return '本金';
                    if (parseInt(item.feeClsCd) == 2) return '利息';
                    if (parseInt(item.feeClsCd) == 3) return '超额抵押';
                    return '其他费用';
                }},
            { display: '还款日', width: 150, name: 'payDt',render:renderDate},
            { display: '应还金额', name: 'feeAmt', width: 160, type: 'float'},
            { display: '已还金额', name: 'paidUpAmt', width: 160, type: 'float'},
            { display: '剩余金额', name: 'arAmt', width: 160, type: 'float',
                totalSummary:
                {
                    render: function (suminf, column, cell)
                    {
                        return '<div>合计:' + suminf.sum + '</div>';
                    },
                    align: 'left'
                }
			},
            { display: '应还金额浮动', name: 'floatAmt',type: 'float', 
                editor: { type: 'float' }, align: 'left', width: 160,
            },
            { display: '本次还款额', name: 'actualAmt',type: 'float', 
                editor: { type: 'float' }, align: 'left', width: 160,
                totalSummary:
                {
                    render: function (suminf, column, cell)
                    {
                        return '<div>' + suminf.sum + '</div>';
                    },
                    align: 'left'
                }
            },
            { display: '备注', name: 'feeRem', width: 200, type: 'text',align: 'left'
            },
            { display: '实际付款时间', name: 'actPymtDt', width: 160, render:renderDate},
            { display: '实际付款金额', name: 'actPymtAmt', width: 160, type: 'text'},
            { display: '机构收款账号', name: 'rcvpymtAccNo', width: 150, type: 'text',
            	render:function (rowdata, rowindex, value, column) { 
            		var h="";
	            	if(rowdata.rcvpymtAccId!=null){
            			 h ="<a href='#' onclick='showInsAcc("+rowdata.rcvpymtAccId+")'> <font color='blue'>"+rowdata.rcvpymtAccNo+"</font></a>";
	            	}
	            	return h;
        		}
            }, 
            { display: '我司付款账户', name: 'payAccNm', width: 200, type: 'text'},
            
            { display: '我司付款账号', name: 'payAccNo', width: 200, type: 'text',
            	render:function (rowdata, rowindex, value, column) { 
	            	var h="";
	            	if(rowdata.payAccId!=null){
            		 h ="<a href='#' onclick='showSysAcc("+rowdata.payAccId+")'> <font color='blue'>"+rowdata.payAccNo+"</font></a>";
	            	}
	            	return h;
            	}
            },
            { display: '逻辑序号', name: 'id',width:0, align:'left', hide:true}
            ],
            enabledEdit: false, isScroll: true,rownumbers:true,
            onAfterShowData: f_onAfterShowData,
            width: '100%',height:350,checkbox:true,usePager:false
        });
    }

    //加载默认选中行
    function f_onAfterShowData(currentData){
    	var sumFeeAmt = 0;
    	if(currentData!=null){
	    	var arr = eval(currentData);      
	        var rows = arr.Rows;
            var manager = $("#cost1").ligerGetGridManager();
	        for(var i=0;i<rows.length;i++){
	        	if(rows[i].actualAmt!=null && rows[i].actualAmt != 0){
            		manager.select(i);
	        	}
	        	if(rows[i].feeClsCd == 1){
	        		sumFeeAmt = accAdd(sumFeeAmt , rows[i].feeAmt);
	        	}
	        }
	        $("#sumFeeAmt").val(sumFeeAmt);
    	}
    }


	//加法函数，用来得到精确的加法结果
	//说明：javascript的加法结果会有误差，在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
	//调用：accAdd(arg1,arg2)
	//返回值：arg1加上arg2的精确结果
	function accAdd(arg1,arg2){
	 var r1,r2,rr,m,maxlen,result;
	 try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
	 try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}	 
	 console.log("length:"+r1+"_"+r2);
	 maxlen = Math.max(r1,r2);
	 m=Math.pow(10,maxlen);
	 console.log("Math.pow:"+m);
	 result = (arg1*m+arg2*m)/m;
	 console.log("result:"+result);
	 return result.toFixed(maxlen);
	}
    //加载默认选中行
    function f_onAfterShowData0(currentData){
    	if(currentData!=null){
	    	var arr = eval(currentData);      
	        var rows = arr.Rows;
            var manager = $("#cost0").ligerGetGridManager();
	        for(var i=0;i<rows.length;i++){
	        	if(rows[i].ACTUAL_AMT!=null && rows[i].ACTUAL_AMT != 0){
            		manager.select(i);
	        	}
	        }
    	}
    }

	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	   //查询项目详情 
	    function detailBtn(id){
	    	var callback = function(){
				 grid.reload();
			}
	    	var timestamp=new Date().getTime();
			Add_navTab('tab_project_detail'+timestamp,'项目基本信息详情','<%=path%>/rfbuss/fncprjbscinfo/toDetailPage1.do?id='+id,callback);
		}
	   //查询报价详情
		function showDetail(id){
			var callback = function(){
				 grid.reload();
			}
			var timestamp=new Date().getTime();
			Add_navTab( 'tab_scm_bsc_info_detl'+timestamp,'查看融资报价','<%=path%>/rfbase/scmbaseinfo/toDetail.do?id='+id,callback);
	  	}
	</script>
</body>
</html>